<?php
/**
 * #Celebrate Shieh
 *             ,%%%%%%%%,
 *           ,%%/\%%%%/\%%
 *          ,%%%\c "" J/%%%
 * %.       %%%%/ o  o \%%%
 * `%%.     %%%%    _  |%%%
 *  `%%     `%%%%(__Y__)%%'
 *  //       ;%%%%`\-/%%%'
 * ((       /  `%%%%%%%'
 *  \\    .'          |
 *   \\  /       \  | |
 *    \\/         ) | |
 *     \         /_ | |__
 *     (___________))))))) 攻城湿
 *
 *        _       _
 * __   _(_)_   _(_) __ _ _ __
 * \ \ / / \ \ / / |/ _` |'_ \
 *  \ V /| |\ V /| | (_| | | | |
 *   \_/ |_| \_/ |_|\__,_|_| |_|
 */

namespace App\Services;

use App\Models\Mongo\Admin;
use App\Models\Mongo\Blog;
use Illuminate\Http\Request;

class BrowseService
{

    use Service;

    /**
     * 浏览日志首页
     *
     * @param Request $request
     *
     * @return string
     */
    public function BrowseIndexService( $request )
    {
        switch ( $request->input('category', 0) ) {
            case 0:
                $browse = Admin::PaginateModel();//获取mongodb 数据并分页
                break;
            case 1:
                $browse = Blog::PaginateModel();//获取mongodb 数据并分页
                break;
            default:
                $browse = '';
                break;
        }
        $browse->appends([
            'category' => $request->input('category', 0),
        ])->render();
        return $browse;
    }

    /**
     * 删除
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function BrowseDestroyService( $request )
    {
        switch ( $request->input('category') ) {
            case 0:
                Admin::DestroyModel($request->input('id'));
                break;
            case 1:
                Blog::DestroyModel($request->input('id'));
                break;
            default:
                return message($this->getErrorCode()::message(1001));
                break;
        }
        return data();
    }

    /**
     * 清空
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function BrowseTruncateService( $request )
    {
        switch ( $request->input('truncate') ) {
            case 'admin':
                Admin::TruncateModel();
                break;
            case 'blog':
                Blog::TruncateModel();
                break;
            default:
                return message($this->getErrorCode()::message(1001));
                break;
        }
        return data();
    }
}
